<template>
  <div class="register-container">
    <div class="register-box">
      <h2 class="register-title">欢迎注册</h2>
      <el-form
        :model="registerData"
        status-icon
        label-width="100px"
        class="register-form"
      >
        <el-form-item label="用户名：">
          <el-input 
            v-model="registerData.uname" 
            type="text" 
            placeholder="请输入用户名"
            prefix-icon="User"
          />
        </el-form-item>
        <el-form-item label="密码：">
          <el-input 
            v-model="registerData.pwd" 
            type="password" 
            show-password 
            placeholder="请输入密码"
            prefix-icon="Lock" 
          />
        </el-form-item>
        <el-form-item label="确认密码：">
          <el-input 
            v-model="registerData.rePwd" 
            @blur="rePwdPattern" 
            type="password" 
            show-password 
            placeholder="请再次输入密码"
            prefix-icon="Lock"
          />
        </el-form-item>
        <el-form-item label="用户昵称：">
          <el-input 
            v-model="registerData.nikeName" 
            minlength="5" 
            type="text" 
            placeholder="请输入昵称(最少5位字符)"
            prefix-icon="UserFilled"
          />
        </el-form-item>
        <el-form-item label="手机号：">
          <el-input 
            v-model="registerData.phone" 
            @blur="phonePattern" 
            type="text" 
            placeholder="请输入手机号"
            prefix-icon="Iphone"
          />
        </el-form-item>
        <el-form-item label="邮箱：">
          <el-input 
            v-model="registerData.email" 
            @blur="emailPattern" 
            type="text" 
            placeholder="请输入邮箱"
            prefix-icon="Message"
          />
        </el-form-item>
        <el-form-item label="性别：">
          <el-radio-group v-model="registerData.sex">
            <el-radio value="1">男</el-radio>
            <el-radio value="2">女</el-radio>
            <el-radio value="3">不详</el-radio>
          </el-radio-group>
        </el-form-item>
        <el-form-item label="年龄：">
          <el-slider 
            v-model="registerData.age"
            :min="1"
            :max="120"
            :step="1"
            show-input
          />
        </el-form-item>

        <el-form-item class="btn-group">
          <el-button type="primary" @click="register" class="submit-btn">
            立即注册
          </el-button>
          <el-link 
            type="primary"
            style="margin-left: 20px;" 
            @click="drawerReg = false;drawerLogin = true"
          >
            已有账号？返回登录
          </el-link>
        </el-form-item>

      </el-form>
    </div>
  </div>
</template>

<script setup>
import { ref, reactive } from 'vue'
import { ElMessage } from 'element-plus'

const registerData = reactive({
  uname: '',
  pwd: '',
  rePwd: '',
  nikeName: '',
  phone: '',
  email: '',
  sex: '3',
  age: 18
})

const register = function(){
  if (registerData.uname === '' || registerData.uname.length === 0) {
    ElMessage({
      message: '用户名不能为空！',
      type: 'warning',
    })
  }else if(registerData.pwd === '' || registerData.pwd.length === 0){
    ElMessage({
      message: '密码不能为空！', 
      type: 'warning',
    })
  }else if(registerData.rePwd === '' || registerData.rePwd.length === 0){
    ElMessage({
      message: '确认密码不能为空！',
      type: 'warning',
    })
  }else if(registerData.nikeName === '' || registerData.nikeName.length < 5){
    ElMessage({
      message: '昵称不能为空且长度不能少于5位!',
      type: 'warning',
    })
  }else if(registerData.phone === '' || registerData.phone.length !== 11){
    ElMessage({
      message: '手机号不能为空且长度必须为11位!',
      type: 'warning',
    })
  }else if(registerData.email === '' || registerData.email.length === 0){
    ElMessage({
      message: '邮箱不能为空!',
      type: 'warning',
    })
  }
  console.log(registerData)
}
</script>

<style scoped>
.register-container {
  display: flex;
  justify-content: center;
  align-items: center;
  min-height: 100vh;
  background: linear-gradient(135deg, #e0eafc 0%, #cfdef3 100%);
  padding: 20px;
}

.register-box {
  background: white;
  padding: 40px;
  border-radius: 15px;
  box-shadow: 0 8px 24px rgba(0,0,0,0.1);
  width: 100%;
  max-width: 600px;
}

.register-title {
  text-align: center;
  color: #409EFF;
  margin-bottom: 30px;
  font-size: 28px;
}

.register-form {
  margin-top: 20px;
}

.btn-group {
  text-align: center;
  margin-top: 30px;
}

.submit-btn {
  width: 140px;
  height: 40px;
  font-size: 16px;
}

:deep(.el-form-item) {
  margin-bottom: 25px;
}

:deep(.el-input) {
  border-radius: 8px;
}

:deep(.el-radio) {
  margin-right: 20px;
}

:deep(.el-slider) {
  width: 90%;
}
</style>